package practicaspl.ocho;

import java.io.IOException;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

import practicaspl.ocho.AnalisisLexer;
import practicaspl.ocho.AnalisisParser;


/**
 * Hello world!
 *
 */
public class Appocho 
{
    public static void main( String[] args ) throws IOException, RecognitionException
    {
    	if(args[0].equals("Calculadora")){
        //System.out.println( "Hello World!" );
        CharStream fis = new ANTLRFileStream("Entrada.txt");
        AnalisisLexer analex = new AnalisisLexer(fis);
        CommonTokenStream tokens = new CommonTokenStream();
        AnalisisParser sint = new AnalisisParser(tokens);
        

        tokens.setTokenSource(analex);

        //System.out.println(tokens.toString());
        //sint.entrada();
        sint.entrada();
    }
    	if(args[0].equals("C")){
            CharStream fis = new ANTLRFileStream("EntradaC.txt");
            AnalisisLexer analex = new AnalisisLexer(fis);
            CommonTokenStream tokens = new CommonTokenStream();
            AnalisisParser sint = new AnalisisParser(tokens);
            

            tokens.setTokenSource(analex);

            System.out.println(tokens.toString());
           // while(tokens.getNumberOfOnChannelTokens() != Token.EOF_TYPE) {
            	//System.out.println(tokens.toString());
            //	tokens = (CommonTokenStream) analex.nextToken();
            //}

            //Anasint anasint = new Anasint(tokens);
            sint.codigoC();
     	}
    	
    	if(args[0].equals("FORMAT")){
            CharStream fis = new ANTLRFileStream("Entradafor.txt");
            AnalisisLexer analex = new AnalisisLexer(fis);
            CommonTokenStream tokens = new CommonTokenStream();
            AnalisisParser sint = new AnalisisParser(tokens);
       
            tokens.setTokenSource(analex);
            
            String Formateo =sint.reglas();
            System.out.println("Foemateado : " + Formateo);
     	}
    	
    	if(args[0].equals("XML")){
            CharStream fis = new ANTLRFileStream("EntradaXML.txt");
            AnalisisLexer analex = new AnalisisLexer(fis);
            CommonTokenStream tokens = new CommonTokenStream();
            AnalisisParser sint = new AnalisisParser(tokens);
       
            tokens.setTokenSource(analex);
            
            sint.entradaxml();
     	}
    }
}
